<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>投票</title>
    <link rel="stylesheet" href="<c:url value='/resource/css/osyear/main.css'></c:url>">
    <script language="JavaScript" src="<c:url value='/resource/js/jquery-2.0.min.js'/>"></script>
    <script type="JavaScript" href="<c:url value='/resource/js/osyear/layer/layer.js'></c:url>" ></script>
    <script type="text/javascript">
        Array.prototype.remove = function(val) {
            var index = this.indexOf(val);
            if (index > -1) {
                this.splice(index, 1);
            }
        };
        var tp_show = new Array();
        function toupiao(id){
            if($("#tp_"+id).hasClass("li_bottom_hov")){

                tp_show.remove(id);
                $("#tp_"+id).removeClass("li_bottom_hov");
            }else{
                if(tp_show.length==3){
                    alert("每人最多投3票！");
                }else{
                    tp_show.push(id);
                    $("#tp_"+id).addClass("li_bottom_hov");
                }
            }
        }

        function applyTp()
        {
                if(tp_show.length==0){
                    alert("请投票后提交！");
                }else{

                    $.ajax({

                        url:'<c:url value="/api/vote/uservote" />',
                        type: "post",
                        dataType :"json",
                        data:{
                            showids:tp_show.toString()
                        },
                        success: function (data) {
                           window.location.href="<c:url value="/api/vote/endVote" />";
                        },
                        error: function () {
                        }

                    });
                }
        }
    </script>
</head>

<body>
<div class="toup">
    <ul class="toup_ul">
        <c:forEach var="show" items="${shows}">
            <li class="li1">
                <div class="li_top">
                    <c:if test="${not empty show.pic}">
                    <img src="data:image/png;base64,${show.pic}" />
                    </c:if>
                    <c:if test="${ empty show.pic}">
                        <img src="<c:url value='/static/osyear/images/pic_a.png'/>" />
                    </c:if>
                </div>
                <div>
                        ${show.name}
                </div>
                <div class="li_bottom" id="tp_${show.id}" onclick="toupiao('${show.id}')">
                    <div class="li_bottom_lf" ></div>
                    投票
                </div>
            </li>
        </c:forEach>
    </ul>
</div>
<div class="jmxq_btn">
    <a href="javascript:applyTp()">提交</a>
</div>
</div>
<script>
//    $(document).ready(function(){
//        $(".toup_ul>li:odd").css("marginLeft","4%");
//        $(".toup_ul > li").click(function(){
//            $(this).addClass("li1").siblings("li").removeClass("li1");
//            $(this).children(".li_bottom").addClass("li_bottom_hov");
//            $(this).siblings("li").children(".li_bottom").removeClass("li_bottom_hov");
//        });
//    })
</script>
</body>

</html>